/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package com.zzb.framework.modules.oss.cloud;


import com.zzb.framework.enums.CloudServiceEnums;
import com.zzb.framework.modules.param.service.SysParamService;
import com.zzb.framework.utils.ConfigConstant;
import com.zzb.framework.utils.SpringContextHolder;

/**
 * 文件上传Factory
 *
 * @author Mark sunlightcs@gmail.com
 */
public final class OSSFactory {
    private static SysParamService sysParamService;

    static {
        OSSFactory.sysParamService = SpringContextHolder.getBean("sysParamService");
    }

    public static CloudStorageService build(){
        //获取云存储配置信息
        CloudStorageConfig config = sysParamService.getJSONObject(ConfigConstant.CLOUD_STORAGE_CONFIG_KEY, CloudStorageConfig.class);

        if(config.getType().equals(CloudServiceEnums.QINIU.getValue())){
            return new QiniuCloudStorageService(config);
        }else if(config.getType().equals(CloudServiceEnums.ALIYUN.getValue())){
            return new AliyunCloudStorageService(config);
        }else if(config.getType().equals(CloudServiceEnums.QCLOUD.getValue())){
            return new QcloudCloudStorageService(config);
        }

        return null;
    }

}
